Python Programming for Beginners by Cannon Jason
Author:Cannon, Jason
Language: eng
Format: epub
Tags: Python
Published: 2014-08-27T16:00:00+00:00
Resources
DRY: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
Documentation for the help() built-in function: https://docs.python.org/3/library/functions.html#help
Docstring Conventions (PEP 257): http://legacy.python.org/dev/peps/pep-0257/
Chapter 5 - Lists
So far you have learned about the string, integer, float, and boolean data types. A list is a data type that holds an ordered collection of items. The items, or values, contained in a list can be various data types themselves. You can even have lists within lists.
Lists are created using comma separated values between square brackets. The format is list_name = [item_1, item_2, item_N]. To create an empty list use: list_name = []. Items in a list can be accessed by index. List indices are zero based, meaning that the first item in the list has an index of 0, the second item has an index of 1, etc. To access an item in a list using an index, enclose the index in square brackets immediately following the list name. The format is list_name[index].
animals = ['man', 'bear', 'pig'] print(animals[0]) print(animals[1]) print(animals[2])
Output:
man bear pig
Not only can you access values by index, you can also set values by index.
animals = ['man', 'bear', 'pig'] print(animals[0]) animals[0] = 'cat' print(animals[0])
Output:
man cat
You can access items starting at the end of the list by using a negative index. The -1 index represents the last item in the list, -2 represents the second to last item in the list, and so on.
animals = ['man', 'bear', 'pig'] print(animals[-1]) print(animals[-2]) print(animals[-3])
Output:
pig bear man
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
What's Done in Darkness by Kayla Perrin(26519)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19005)
The Fifty Shades Trilogy & Grey by E L James(18955)
Shot Through the Heart by Mercy Celeste(18877)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(16979)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16870)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16800)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16693)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16319)
The Subtle Art of Not Giving a F*ck by Mark Manson(14253)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14069)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13416)
Scorched Earth by Nick Kyme(12710)
Drei Generationen auf dem Jakobsweg by Stein Pia(10919)
Suna by Ziefle Pia(10844)
Scythe by Neal Shusterman(10267)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9473)
Successful Proposal Strategies for Small Businesses: Using Knowledge Management ot Win Govenment, Private Sector, and International Contracts 3rd Edition by Robert Frey(9314)
This is Going to Hurt by Adam Kay(9092)
